#!/bin/bash
#redis监控脚本

#redis IP和端口
read -p "请输入Redis服务器的IP地址: " REDIS_IP
read -p "请输入Redis服务器的端口号: " REDIS_PORT

# 使用redis-cli连接到指定的Redis实例
REDIS_INFO=$(redis-cli -h $REDIS_IP -p $REDIS_PORT info)

# 检查是否成功连接
if [ $? -ne 0 ]; then
    echo "无法连接到Redis服务器 $REDIS_IP:$REDIS_PORT"
    exit 1
fi

#PID
echo "PID"
echo "$REDIS_INFO" | grep 'process_id:'

#CPU占用
echo "CPU:"
echo "$REDIS_INFO" | grep 'used_cpu_sys:'
echo "$REDIS_INFO" | grep 'used_cpu_user:'

#查看RSS内存占用
echo "RSS 内存占用:"
echo "$REDIS_INFO" | grep 'used_memory_rss:'
echo "$REDIS_INFO" | grep 'used_memory_rss_human:'

#查看接收的连接数、拒绝连接数
echo "接收的连接数、拒绝连接数:"
echo "$REDIS_INFO" | grep 'total_connections_received:'
echo "$REDIS_INFO" | grep 'rejected_connections:'


# 显示网卡流入流出流量
echo "网卡流入流出流量:"
echo "$REDIS_INFO" | grep 'instantaneous_input_kbps' 
echo "$REDIS_INFO" | grep 'instantaneous_output_kbps'

# 显示缓存命中数和丢失数
echo "缓存命中数和丢失数:"
echo "$REDIS_INFO" | grep 'keyspace_hits:'
echo "$REDIS_INFO" | grep 'keyspace_misses:'
